package hr.fer.apr.ht41337.lab3;

public class Tocka {
	public final int dimenzija;
	private double[] x;
	
	Tocka(int dimenzija)
	{
		this.dimenzija = dimenzija;
		x = new double[dimenzija];
	}
	
	public double getX(int i)
	{
		return x[i];
	}
	
	public void setX(int i, double value)
	{
		x[i] = value;
	}
	
	@Override
	public Tocka clone()
	{
		Tocka copy = new Tocka(dimenzija);
		for (int i = 0; i < dimenzija; i++)
			copy.setX(i, x[i]);
		return copy;
	}
	
	public Tocka plus(Tocka t)
	{
		if (t.dimenzija != dimenzija)
			throw new IllegalArgumentException("tocke nisu istih dimenzija");
		Tocka sum = new Tocka(dimenzija);
		for (int i = 0; i < dimenzija; i++)
			sum.setX(i, this.x[i] + t.x[i]);
		return sum;
	}
	
	public Tocka times(double d)
	{
		Tocka product = new Tocka(dimenzija);
		for (int i = 0; i < dimenzija; i++)
			product.setX(i, d * x[i]);
		return product;
	}
	
	@Override
	public String toString()
	{
		String s = "(" + x[0];
		for (int i = 1; i < x.length; i++)
			s += "," + x[i];
		s += ")";
		return s;
	}
}
